package com.nio.channel;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

/**
 * @author liyanhao
 * @Date 2023-01-12 10:36
 */
public class FileChannelWriteDemo {
    public static void main(String[] args) throws IOException {
        RandomAccessFile file1 =
                new RandomAccessFile("D:\\ideaProjects\\JavaTechnologyLearn\\java-8017\\java-nio\\src\\main\\java\\com\\nio\\channel\\FileChannelWriteDemo.java", "rw");
        RandomAccessFile file2 =
                new RandomAccessFile("FileChannelDemo2.java", "rw");
        FileChannel channel1 = file1.getChannel();
        FileChannel channel2 = file2.getChannel();
        long size = channel1.size();
        channel2.transferFrom(channel1, 0, size);
        file1.close();
        file2.close();
        System.out.println("over");

    }
}
